package com.allinpay;

import java.util.StringJoiner;

/**
 * @author : wushikai
 * <p>
 * date : 2020-11-19
 */
public class StringJoinerDemo {


    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        sb.append("hello");
        sb.append(",");
        sb.append("guys");
        sb.append(",");
        sb.append("欢迎关注公众号Java技术栈");
        String str = sb.toString();
        System.out.println(str);

        //怎么写会更加简洁一些;
        str = String.join(",", "hello", "guys", "欢迎关注公众号Java技术栈");
        System.out.println(str);

        /*使用StringJoiner*/
        StringJoiner stringJoiner = new StringJoiner(",");
        stringJoiner.add("hello");
        stringJoiner.add("guys");
        stringJoiner.add("欢迎关注公众号Java技术栈");
        System.out.println(stringJoiner.toString());


        //需要指定前后缀：
        stringJoiner = new StringJoiner(",", "[", "]");
        stringJoiner.add("hello");
        stringJoiner.add("guys");
        stringJoiner.add("欢迎关注公众号Java技术栈");
        System.out.println(stringJoiner.toString());  //[hello,guys,欢迎关注公众号Java技术栈]





    }


}
